itemlst = {'F00001':{'name':'Apple','price':'1.2'},'F00002':{'name':'Banana','price':'5.5'}}
userlst = {'root':'123456'}
cart = set()
budget = 0
def exit():
    if not cart:
        print("your shop cart do npt have anything")
    else:
        print(f"you have buy this goods: {cart}")
    print(f"your budget have:{budget}")
    sys.exit(0)
def login(str):
    if user in userlst:
        password = input("input your password:")
        if password == userlst.get('root'):
            print("login successful!\nplease inpuy your budget later")
            Budget()
        elif password == "exit":
            exit()
        else:
            print("your password is not right,please input again")
            login(user)
    else:
        print("your user is not exist，please inpuy again")

def Budget():
    global budget
    A = input("please input your budget")
    if A == "exit":
        exit()
    elif A.isdigit():
        budget = float(A)
        shopping()
    else:
        print("The character types which you input is not right,please input again")
        Budget()

def shopping():
    global budget
    X = input("if you want see shop iteml please input buy\nexit input exit\nsee shop cart input cart\n")
    if X == "buy":
        for key in itemlst:
            print(f"product id is “{key}”,information is {itemlst[key]}")
        print("please input the id which you want to buy:")
        buying = input()
        if buying in itemlst and budget > float(itemlst.get(buying).get("price")):
            cart.add(itemlst.get(buying).get("name"))
            budget -= float(itemlst.get(buying).get("price"))
            print(f"You have buy {itemlst.get(buying).get('name')}")
            shopping()
        elif buying in itemlst and float(budget) < float(itemlst.get(buying).get("price")):
            print("Your budget is not enough")
            shopping()
        elif buying == "exit" :
             exit()
        else:
            print("The id is nou right,please input again")
            shopping()
    elif X == "cart":
        if not cart:
            print("your shop cart do npt have anything")
            shopping()
        else:
            print(f"Your shopping cart have following items:{cart}")
            shopping()
    elif X == "exit":
        exit()
    else:
        print("The input is nou right,please input again")
        shopping()

# def login2(username, passwd):
#     if  验证登录：
#         return 1
#     return  0
import sys
while True:
        user=input("please input your username：")
        if user == "exit":
            exit()
        login(user)
        # user = input("please input your username：")
        # if login2():
        #     buget()
